package org.zcl.feign.fallback;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.stereotype.Component;
import org.zcl.feign.UserServiceFeignClient;

/**
 * .
 *
 * @Author Chenglin Zhu
 * @Date 2022/1/23 7:33 下午
 */
@Component
@Slf4j
public class UserServiceFeignClientFallbackFactory implements FallbackFactory<UserServiceFeignClient> {

    @Override
    public UserServiceFeignClient create(Throwable cause) {
        return new UserServiceFeignClient() { // <2>

            @Override
            public String getUser(Integer id) {
                log.info("[getUserFallback][id({}) exception({})]", id, ExceptionUtils.getRootCauseMessage(cause));
                return "mock:User:" + id;
            }
        };
    }
}
